extends ItemList

var unit_scene : PackedScene
var unit_instance 
var fs_path : String

onready var World = get_parent().get_node("VBoxContainer/ViewportContainer/Viewport/World")

func _ready():
	pass


func _on_UnitList_item_activated(index):
	var item = get_item_text(index)
	if typeof(item) == TYPE_STRING and fs_path:
		unit_instance and unit_instance.queue_free()
		unit_scene = load(fs_path + "/" + item + ".tscn")
		unit_instance = unit_scene.instance()
		unit_instance.position = Vector2()
		World.get_node("PlayerUnits").add_child(unit_instance)
		get_parent().get_node("VBoxContainer/SpeedParameter").value = String(unit_instance.speed)
		get_parent().get_node("VBoxContainer/AttackParameter").value = String(unit_instance.attack)
		get_parent().get_node("VBoxContainer/DefenseParameter").value = String(unit_instance.defense)
